/**  
 * All rights Reserved, Designed By www.beonelot.com
 * @Package: com.bccah.modlib.dbdo.controller
 * @Filename: AcsControlUserMethodController.java
 * @Description: TODO(AcsControlUserMethodController)
 * @author: 金鑫智慧
 * @date: 2020-04-08
 * @version: V1.0
 * @Copyright: 2018 www.beonelot.com Inc. All rights reserved.
 * 注意：本内容仅限于重庆金鑫智慧科技有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
package com.jinxin.platform.cdfaceacs.controller;

import com.alibaba.fastjson.JSON;
import com.jinxin.platform.cdfaceacs.common.CommonCodeEntity;
import com.jinxin.platform.cdfaceacs.common.ResultEntity;
import com.jinxin.platform.cdfaceacs.pojo.domains.AcsControlUserMethodDO;
import com.jinxin.platform.cdfaceacs.service.AcsControlUserMethodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * TODO(AcsControlUserMethodController)
 * @Classn: AcsControlUserMethodController
 * @author SY
 * @date 2020-04-08
 */
@RestController
@RequestMapping("/basicUserMethod")
@Slf4j
public class AcsControlUserMethodController {

    @Autowired
    private AcsControlUserMethodService userMethodService;

    /**
     * 获取某用户访问方式记录
     * @return
     */
    @PostMapping("/selUserTypeList")
    public ResultEntity selTypeList(String key, String user ){
        AcsControlUserMethodDO userMethodDO = new AcsControlUserMethodDO();
        if(!StringUtils.isEmpty(key)){
            userMethodDO.setVisitorMethodKey(key);
        }
        if(!StringUtils.isEmpty(user)){
            userMethodDO.setUserId(user);
        }
        List<AcsControlUserMethodDO> infoDOList = userMethodService.selDOByInfo(userMethodDO);
        return new ResultEntity(CommonCodeEntity.SUC_CODE,"suc",infoDOList);
    }

    /**
     * 更新用户的访客访问类型
     * @param uid
     * @param keys
     * @return
     */
    @PostMapping("/upTypeList")
    public ResultEntity upTypeList(String uid,String keys ){
        userMethodService.delDO(uid );
        List<String> keyList = JSON.parseArray(keys, String.class);
        AcsControlUserMethodDO plugListDO;
        for(String key:keyList ){
            plugListDO = new AcsControlUserMethodDO();
            plugListDO.setVisitorMethodKey(key);
            plugListDO.setUserId(uid);
            plugListDO.setCreateTime(LocalDateTime.now());
            userMethodService.saveDO(plugListDO);
        }
        return new ResultEntity(CommonCodeEntity.SUC_CODE,"suc","" );
    }


}
